{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f3b11b5c-987d-46f3-956d-3004db6d2344",
   "metadata": {},
   "source": [
    "# Unemployment in the US since 1967"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "00fe4a2f-4bd0-4ab5-be23-461dd2c7c43f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"115i2v\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.4.0/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"115i2v\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"115i2v\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "            <div id=\"kotlin_out_0\"></div>\n",
       "            <script type=\"text/javascript\">\n",
       "                            if(!window.kotlinQueues) {\n",
       "                window.kotlinQueues = {};\n",
       "            }\n",
       "            if(!window.kotlinQueues[\"DataFrame\"]) {\n",
       "                var resQueue = [];\n",
       "                window.kotlinQueues[\"DataFrame\"] = resQueue;\n",
       "                window[\"call_DataFrame\"] = function(f) {\n",
       "                    resQueue.push(f);\n",
       "                }\n",
       "            }\n",
       "            (function (){\n",
       "                var modifiers = [(function(script) {\n",
       "    script.src = \"https://cdn.jsdelivr.net/gh/Kotlin/dataframe@3db46ccccaa1291c0627307d64133317f545e6ae/core/src/main/resources/init.js\"\n",
       "    script.type = \"text/javascript\";\n",
       "})];\n",
       "                var e = document.getElementById(\"kotlin_out_0\");\n",
       "                modifiers.forEach(function (gen) {\n",
       "                    var script = document.createElement(\"script\");\n",
       "                    gen(script)\n",
       "                    script.addEventListener(\"load\", function() {\n",
       "                        window[\"call_DataFrame\"] = function(f) {f();};\n",
       "                        window.kotlinQueues[\"DataFrame\"].forEach(function(f) {f();});\n",
       "                        window.kotlinQueues[\"DataFrame\"] = [];\n",
       "                    }, false);\n",
       "                    script.addEventListener(\"error\", function() {\n",
       "                        window[\"call_DataFrame\"] = function(f) {};\n",
       "                        window.kotlinQueues[\"DataFrame\"] = [];\n",
       "                        var div = document.createElement(\"div\");\n",
       "                        div.style.color = 'darkred';\n",
       "                        div.textContent = 'Error loading resource DataFrame';\n",
       "                        document.getElementById(\"kotlin_out_0\").appendChild(div);\n",
       "                    }, false);\n",
       "                    \n",
       "                    e.appendChild(script);\n",
       "                });\n",
       "            })();\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "                <style>\n",
       "                :root {\n",
       "    --background: #fff;\n",
       "    --background-odd: #f5f5f5;\n",
       "    --background-hover: #d9edfd;\n",
       "    --header-text-color: #474747;\n",
       "    --text-color: #848484;\n",
       "    --text-color-dark: #000;\n",
       "    --text-color-medium: #737373;\n",
       "    --text-color-pale: #b3b3b3;\n",
       "    --inner-border-color: #aaa;\n",
       "    --bold-border-color: #000;\n",
       "    --link-color: #296eaa;\n",
       "    --link-color-pale: #296eaa;\n",
       "    --link-hover: #1a466c;\n",
       "}\n",
       "\n",
       ":root[theme=\"dark\"], :root [data-jp-theme-light=\"false\"], .dataframe_dark{\n",
       "    --background: #303030;\n",
       "    --background-odd: #3c3c3c;\n",
       "    --background-hover: #464646;\n",
       "    --header-text-color: #dddddd;\n",
       "    --text-color: #b3b3b3;\n",
       "    --text-color-dark: #dddddd;\n",
       "    --text-color-medium: #b2b2b2;\n",
       "    --text-color-pale: #737373;\n",
       "    --inner-border-color: #707070;\n",
       "    --bold-border-color: #777777;\n",
       "    --link-color: #008dc0;\n",
       "    --link-color-pale: #97e1fb;\n",
       "    --link-hover: #00688e;\n",
       "}\n",
       "\n",
       "p.dataframe_description {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe {\n",
       "    font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n",
       "    font-size: 12px;\n",
       "    background-color: var(--background);\n",
       "    color: var(--text-color-dark);\n",
       "    border: none;\n",
       "    border-collapse: collapse;\n",
       "}\n",
       "\n",
       "table.dataframe th, td {\n",
       "    padding: 6px;\n",
       "    border: 1px solid transparent;\n",
       "    text-align: left;\n",
       "}\n",
       "\n",
       "table.dataframe th {\n",
       "    background-color: var(--background);\n",
       "    color: var(--header-text-color);\n",
       "}\n",
       "\n",
       "table.dataframe td {\n",
       "    vertical-align: top;\n",
       "}\n",
       "\n",
       "table.dataframe th.bottomBorder {\n",
       "    border-bottom-color: var(--bold-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(odd) {\n",
       "    background: var(--background-odd);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(even) {\n",
       "    background: var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:hover {\n",
       "    background: var(--background-hover);\n",
       "}\n",
       "\n",
       "table.dataframe a {\n",
       "    cursor: pointer;\n",
       "    color: var(--link-color);\n",
       "    text-decoration: none;\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover > td a {\n",
       "    color: var(--link-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe a:hover {\n",
       "    color: var(--link-hover);\n",
       "    text-decoration: underline;\n",
       "}\n",
       "\n",
       "table.dataframe img {\n",
       "    max-width: fit-content;\n",
       "}\n",
       "\n",
       "table.dataframe th.complex {\n",
       "    background-color: var(--background);\n",
       "    border: 1px solid var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe .leftBorder {\n",
       "    border-left-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightBorder {\n",
       "    border-right-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightAlign {\n",
       "    text-align: right;\n",
       "}\n",
       "\n",
       "table.dataframe .expanderSvg {\n",
       "    width: 8px;\n",
       "    height: 8px;\n",
       "    margin-right: 3px;\n",
       "}\n",
       "\n",
       "table.dataframe .expander {\n",
       "    display: flex;\n",
       "    align-items: center;\n",
       "}\n",
       "\n",
       "/* formatting */\n",
       "\n",
       "table.dataframe .null {\n",
       "    color: var(--text-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe .structural {\n",
       "    color: var(--text-color-medium);\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .dataFrameCaption {\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .numbers {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe td:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "\n",
       "                </style>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot\n",
    "%use dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "76ace100-3139-4d3a-a683-f14fc232adb9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import kotlinx.datetime.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ae2ff904-f7fd-461f-a5f5-3b901a31f98b",
   "metadata": {},
   "outputs": [],
   "source": [
    "fun LocalDateTime.toMillis(): Long {\n",
    "    return toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds()\n",
    "}\n",
    "\n",
    "fun LocalDateTime.Companion.fromYear(year: Int): LocalDateTime {\n",
    "    return LocalDateTime(year, 1, 1, 0, 0)\n",
    "}\n",
    "\n",
    "fun DataFrame<*>.parseDates(column: String): DataFrame<*> {\n",
    "    return this.convert(column).toLocalDateTime()\n",
    "               .convert(column).with { (it as LocalDateTime).toMillis() }\n",
    "}\n",
    "\n",
    "fun millisByYear(year: Int): Long {\n",
    "    return LocalDateTime.fromYear(year).toMillis()\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "615d5402-4a42-427f-b0ef-e9ee17c990bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "val presidentialDf = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/presidential.csv\")\n",
    "    .parseDates(\"start\").parseDates(\"end\")\n",
    "val economicsDf = DataFrame.readCSV(\"https://vincentarelbundock.github.io/Rdatasets/csv/ggplot2/economics.csv\")\n",
    "    .parseDates(\"date\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0532a832-c389-44af-bc36-05e7b4a549ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"VkYrTg\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"ggtitle\":{\n",
       "\"text\":\"Unemployment in the US\",\n",
       "\"subtitle\":\"1967 to 2015\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"guides\":{\n",
       "\"fill\":{\n",
       "\"name\":\"legend\",\n",
       "\"override_aes\":{\n",
       "\"color\":\"paper\",\n",
       "\"alpha\":0.4\n",
       "}\n",
       "}\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"cartesian\",\n",
       "\"xlim\":[-1.262124E11,1.4516244E12],\n",
       "\"flip\":false\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":1000.0,\n",
       "\"height\":400.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"datetime\":true,\n",
       "\"name\":\"Year\"\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"breaks\":[2500.0,5000.0,10000.0],\n",
       "\"name\":\"Unemployment (x\\\\(10^3\\\\))\",\n",
       "\"labels\":[\"2.5\",\"5.0\",\"10.0\"],\n",
       "\"trans\":\"log10\"\n",
       "},{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"discrete\":true,\n",
       "\"name\":\"\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"start\",\n",
       "\"xmax\":\"end\",\n",
       "\"fill\":\"party\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"data\":{\n",
       "\"start\":[-5.34798E11,-2.823372E11,-1.928268E11,-2.98764E10,1.452528E11,2.225844E11,3.488148E11,6.012756E11,7.27506E11,9.799668E11,1.2324276E12,1.4848884E12],\n",
       "\"end\":[-2.823372E11,-1.928268E11,-2.98764E10,1.452528E11,2.225844E11,3.488148E11,6.012756E11,7.27506E11,9.799668E11,1.2324276E12,1.4848884E12,1.6111188E12],\n",
       "\"party\":[\"Republican\",\"Democratic\",\"Democratic\",\"Republican\",\"Republican\",\"Democratic\",\"Republican\",\"Republican\",\"Democratic\",\"Republican\",\"Democratic\",\"Republican\"]\n",
       "},\n",
       "\"size\":0.0,\n",
       "\"alpha\":0.4,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"name\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"start\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"end\"\n",
       "},{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"party\"\n",
       "}]\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"start\",\n",
       "\"label\":\"name\",\n",
       "\"color\":\"party\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"vjust\":1.0,\n",
       "\"data\":{\n",
       "\"name\":[\"Eisenhower\",\"Kennedy\",\"Johnson\",\"Nixon\",\"Ford\",\"Carter\",\"Reagan\",\"Bush\",\"Clinton\",\"Bush\",\"Obama\",\"Trump\"],\n",
       "\"start\":[-5.34798E11,-2.823372E11,-1.928268E11,-2.98764E10,1.452528E11,2.225844E11,3.488148E11,6.012756E11,7.27506E11,9.799668E11,1.2324276E12,1.4848884E12],\n",
       "\"party\":[\"Republican\",\"Democratic\",\"Democratic\",\"Republican\",\"Republican\",\"Democratic\",\"Republican\",\"Republican\",\"Democratic\",\"Republican\",\"Democratic\",\"Republican\"]\n",
       "},\n",
       "\"alpha\":0.6,\n",
       "\"y\":4000.0,\n",
       "\"angle\":90.0,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"label\",\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"name\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"start\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"end\"\n",
       "},{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"party\"\n",
       "}]\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"date\",\n",
       "\"y\":\"unemploy\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"data\":{\n",
       "\"date\":[-7.90416E10,-7.63632E10,-7.36848E10,-7.10928E10,-6.84108E10,-6.58188E10,-6.31404E10,-6.0462E10,-5.79564E10,-5.5278E10,-5.26896E10,-5.00112E10,-4.74192E10,-4.47408E10,-4.20624E10,-3.94704E10,-3.67884E10,-3.41964E10,-3.1518E10,-2.88396E10,-2.64204E10,-2.3742E10,-2.11536E10,-1.84752E10,-1.58832E10,-1.32048E10,-1.05264E10,-7.9344E9,-5.2524E9,-2.6604E9,1.8E7,2.6964E9,5.1156E9,7.794E9,1.03824E10,1.30608E10,1.56528E10,1.83312E10,2.10096E10,2.36016E10,2.62836E10,2.88756E10,3.1554E10,3.42324E10,3.66516E10,3.933E10,4.19184E10,4.45968E10,4.71888E10,4.98672E10,5.25456E10,5.51376E10,5.78196E10,6.04116E10,6.309E10,6.57684E10,6.8274E10,7.09524E10,7.35408E10,7.62192E10,7.88112E10,8.14896E10,8.4168E10,8.676E10,8.9442E10,9.2034E10,9.47124E10,9.73908E10,9.981E10,1.024884E11,1.050768E11,1.077552E11,1.103472E11,1.130256E11,1.15704E11,1.18296E11,1.20978E11,1.2357E11,1.262484E11,1.289232E11,1.313424E11,1.340208E11,1.366128E11,1.392912E11,1.418832E11,1.445616E11,1.4724E11,1.49832E11,1.52514E11,1.55106E11,1.577844E11,1.604628E11,1.628784E11,1.655568E11,1.681488E11,1.708272E11,1.734192E11,1.760976E11,1.78776E11,1.81368E11,1.8405E11,1.86642E11,1.893204E11,1.919988E11,1.945044E11,1.971828E11,1.997712E11,2.024496E11,2.050416E11,2.0772E11,2.103984E11,2.129904E11,2.156724E11,2.182644E11,2.209428E11,2.236212E11,2.260404E11,2.287188E11,2.313072E11,2.339856E11,2.365776E11,2.39256E11,2.419344E11,2.445264E11,2.472084E11,2.498004E11,2.524788E11,2.551572E11,2.575764E11,2.602548E11,2.628432E11,2.655216E11,2.681136E11,2.70792E11,2.734704E11,2.760624E11,2.787444E11,2.813364E11,2.840148E11,2.866932E11,2.891124E11,2.917908E11,2.943792E11,2.970576E11,2.996496E11,3.02328E11,3.050064E11,3.075984E11,3.102804E11,3.128724E11,3.155508E11,3.182292E11,3.207348E11,3.234132E11,3.260016E11,3.2868E11,3.31272E11,3.339504E11,3.366288E11,3.392208E11,3.419028E11,3.444948E11,3.471732E11,3.498516E11,3.522708E11,3.549492E11,3.575376E11,3.60216E11,3.62808E11,3.654864E11,3.681648E11,3.707568E11,3.734388E11,3.760308E11,3.787092E11,3.813876E11,3.838068E11,3.864852E11,3.890736E11,3.91752E11,3.94344E11,3.970224E11,3.997008E11,4.022928E11,4.049748E11,4.075668E11,4.102452E11,4.129236E11,4.153428E11,4.180212E11,4.206096E11,4.23288E11,4.2588E11,4.285584E11,4.312368E11,4.338288E11,4.365108E11,4.391028E11,4.417812E11,4.444596E11,4.469652E11,4.496436E11,4.52232E11,4.549104E11,4.575024E11,4.601808E11,4.628592E11,4.654512E11,4.681332E11,4.707252E11,4.734036E11,4.76082E11,4.785012E11,4.811796E11,4.83768E11,4.864464E11,4.890384E11,4.917168E11,4.943952E11,4.969872E11,4.996692E11,5.022612E11,5.049396E11,5.07618E11,5.100372E11,5.127156E11,5.15304E11,5.179824E11,5.205744E11,5.232528E11,5.259312E11,5.285232E11,5.312052E11,5.337972E11,5.364756E11,5.39154E11,5.415732E11,5.442516E11,5.4684E11,5.495184E11,5.521104E11,5.547888E11,5.574672E11,5.600592E11,5.627412E11,5.653332E11,5.680116E11,5.7069E11,5.731956E11,5.75874E11,5.784624E11,5.811408E11,5.837328E11,5.864112E11,5.890896E11,5.916816E11,5.943636E11,5.969556E11,5.99634E11,6.023124E11,6.047316E11,6.0741E11,6.099984E11,6.126768E11,6.152688E11,6.179472E11,6.206256E11,6.232176E11,6.258996E11,6.284916E11,6.3117E11,6.338484E11,6.362676E11,6.38946E11,6.415344E11,6.442128E11,6.468048E11,6.494832E11,6.521616E11,6.547536E11,6.574356E11,6.600276E11,6.62706E11,6.653844E11,6.678036E11,6.70482E11,6.730704E11,6.757488E11,6.783408E11,6.810192E11,6.836976E11,6.862896E11,6.889716E11,6.915636E11,6.94242E11,6.969204E11,6.99426E11,7.021044E11,7.046928E11,7.073712E11,7.099632E11,7.126416E11,7.1532E11,7.17912E11,7.20594E11,7.23186E11,7.258644E11,7.285428E11,7.30962E11,7.336404E11,7.362288E11,7.389072E11,7.414992E11,7.441776E11,7.46856E11,7.49448E11,7.5213E11,7.54722E11,7.574004E11,7.600788E11,7.62498E11,7.651764E11,7.677648E11,7.704432E11,7.730352E11,7.757136E11,7.78392E11,7.80984E11,7.83666E11,7.86258E11,7.889364E11,7.916148E11,7.94034E11,7.967124E11,7.993008E11,8.019792E11,8.045712E11,8.072496E11,8.09928E11,8.1252E11,8.15202E11,8.17794E11,8.204724E11,8.231508E11,8.256564E11,8.283348E11,8.309232E11,8.336016E11,8.361936E11,8.38872E11,8.415504E11,8.441424E11,8.468244E11,8.494164E11,8.520948E11,8.547732E11,8.571924E11,8.598708E11,8.624592E11,8.651376E11,8.677296E11,8.70408E11,8.730864E11,8.756784E11,8.783604E11,8.809524E11,8.836308E11,8.863092E11,8.887284E11,8.914068E11,8.939952E11,8.966736E11,8.992656E11,9.01944E11,9.046224E11,9.072144E11,9.098964E11,9.124884E11,9.151668E11,9.178452E11,9.202644E11,9.229428E11,9.255312E11,9.282096E11,9.308016E11,9.3348E11,9.361584E11,9.387504E11,9.414324E11,9.440244E11,9.467028E11,9.493812E11,9.518868E11,9.545652E11,9.571536E11,9.59832E11,9.62424E11,9.651024E11,9.677808E11,9.703728E11,9.730548E11,9.756468E11,9.783252E11,9.810036E11,9.834228E11,9.861012E11,9.886896E11,9.91368E11,9.9396E11,9.966384E11,9.993168E11,1.0019088E12,1.0045908E12,1.0071828E12,1.0098612E12,1.0125396E12,1.0149588E12,1.0176372E12,1.0202256E12,1.022904E12,1.025496E12,1.0281744E12,1.0308528E12,1.0334448E12,1.0361268E12,1.0387188E12,1.0413972E12,1.0440756E12,1.0464948E12,1.0491732E12,1.0517616E12,1.05444E12,1.057032E12,1.0597104E12,1.0623888E12,1.0649808E12,1.0676628E12,1.0702548E12,1.0729332E12,1.0756116E12,1.0781172E12,1.0807956E12,1.083384E12,1.0860624E12,1.0886544E12,1.0913328E12,1.0940112E12,1.0966032E12,1.0992852E12,1.1018772E12,1.1045556E12,1.107234E12,1.1096532E12,1.1123316E12,1.11492E12,1.1175984E12,1.1201904E12,1.1228688E12,1.1255472E12,1.1281392E12,1.1308212E12,1.1334132E12,1.1360916E12,1.13877E12,1.1411892E12,1.1438676E12,1.146456E12,1.1491344E12,1.1517264E12,1.1544048E12,1.1570832E12,1.1596752E12,1.1623572E12,1.1649492E12,1.1676276E12,1.170306E12,1.1727252E12,1.1754E12,1.177992E12,1.1806704E12,1.1832624E12,1.1859408E12,1.1886192E12,1.1912112E12,1.1938896E12,1.1964852E12,1.1991636E12,1.201842E12,1.2043476E12,1.2070224E12,1.2096144E12,1.2122928E12,1.2148848E12,1.2175632E12,1.2202416E12,1.2228336E12,1.225512E12,1.2281076E12,1.230786E12,1.2334644E12,1.2358836E12,1.2385584E12,1.2411504E12,1.2438288E12,1.2464208E12,1.2490992E12,1.2517776E12,1.2543696E12,1.257048E12,1.2596436E12,1.262322E12,1.2650004E12,1.2674196E12,1.2700944E12,1.2726864E12,1.2753648E12,1.2779568E12,1.2806352E12,1.2833136E12,1.2859056E12,1.288584E12,1.2911796E12,1.293858E12,1.2965364E12,1.2989556E12,1.3016304E12,1.3042224E12,1.3069008E12,1.3094928E12,1.3121712E12,1.3148496E12,1.3174416E12,1.32012E12,1.3227156E12,1.325394E12,1.3280724E12,1.330578E12,1.3332528E12,1.3358448E12,1.3385232E12,1.3411152E12,1.3437936E12,1.346472E12,1.349064E12,1.3517424E12,1.354338E12,1.3570164E12,1.3596948E12,1.362114E12,1.3647888E12,1.3673808E12,1.3700592E12,1.3726512E12,1.3753296E12,1.378008E12,1.3806E12,1.3832784E12,1.385874E12,1.3885524E12,1.3912308E12,1.39365E12,1.3963248E12,1.3989168E12,1.4015952E12,1.4041872E12,1.4068656E12,1.409544E12,1.412136E12,1.4148144E12,1.41741E12,1.4200884E12,1.4227668E12,1.425186E12,1.4278608E12],\n",
       "\"unemploy\":[2944.0,2945.0,2958.0,3143.0,3066.0,3018.0,2878.0,3001.0,2877.0,2709.0,2740.0,2938.0,2883.0,2768.0,2686.0,2689.0,2715.0,2685.0,2718.0,2692.0,2712.0,2758.0,2713.0,2816.0,2868.0,2856.0,3040.0,3049.0,2856.0,2884.0,3201.0,3453.0,3635.0,3797.0,3919.0,4071.0,4175.0,4256.0,4456.0,4591.0,4898.0,5076.0,4986.0,4903.0,4987.0,4959.0,4996.0,4949.0,5035.0,5134.0,5042.0,4954.0,5161.0,5154.0,5019.0,4928.0,5038.0,4959.0,4922.0,4923.0,4913.0,4939.0,4849.0,4875.0,4602.0,4543.0,4326.0,4452.0,4394.0,4459.0,4329.0,4363.0,4305.0,4305.0,4350.0,4144.0,4396.0,4489.0,4644.0,4731.0,4634.0,4618.0,4705.0,4927.0,5063.0,5022.0,5437.0,5523.0,6140.0,6636.0,7501.0,7520.0,7978.0,8210.0,8433.0,8220.0,8127.0,7928.0,7923.0,7897.0,7794.0,7744.0,7534.0,7326.0,7230.0,7330.0,7053.0,7322.0,7490.0,7518.0,7380.0,7430.0,7620.0,7545.0,7280.0,7443.0,7307.0,7059.0,6911.0,7134.0,6829.0,6925.0,6751.0,6763.0,6815.0,6386.0,6489.0,6318.0,6337.0,6180.0,6127.0,6028.0,6309.0,6080.0,6125.0,5947.0,6077.0,6228.0,6109.0,6173.0,6109.0,6069.0,5840.0,5959.0,5996.0,6320.0,6190.0,6296.0,6238.0,6325.0,6683.0,6702.0,6729.0,7358.0,7984.0,8098.0,8363.0,8281.0,8021.0,8088.0,8023.0,7718.0,8071.0,8051.0,7982.0,7869.0,8174.0,8098.0,7863.0,8036.0,8230.0,8646.0,9029.0,9267.0,9397.0,9705.0,9895.0,10244.0,10335.0,10538.0,10849.0,10881.0,11217.0,11529.0,11938.0,12051.0,11534.0,11545.0,11408.0,11268.0,11154.0,11246.0,10548.0,10623.0,10282.0,9887.0,9499.0,9331.0,9008.0,8791.0,8746.0,8762.0,8456.0,8226.0,8537.0,8519.0,8367.0,8381.0,8198.0,8358.0,8423.0,8321.0,8339.0,8395.0,8302.0,8460.0,8513.0,8196.0,8248.0,8298.0,8128.0,8138.0,7795.0,8402.0,8383.0,8364.0,8439.0,8508.0,8319.0,8135.0,8310.0,8243.0,8159.0,7883.0,7892.0,7865.0,7862.0,7542.0,7574.0,7398.0,7268.0,7261.0,7102.0,7227.0,7035.0,6936.0,6953.0,6929.0,6876.0,6601.0,6779.0,6546.0,6605.0,6843.0,6604.0,6568.0,6537.0,6518.0,6682.0,6359.0,6205.0,6468.0,6375.0,6577.0,6495.0,6511.0,6590.0,6630.0,6725.0,6667.0,6752.0,6651.0,6598.0,6797.0,6742.0,6590.0,6922.0,7188.0,7368.0,7459.0,7764.0,7901.0,8015.0,8265.0,8586.0,8439.0,8736.0,8692.0,8586.0,8666.0,8722.0,8842.0,8931.0,9198.0,9283.0,9454.0,9460.0,9415.0,9744.0,10040.0,9850.0,9787.0,9781.0,9398.0,9565.0,9557.0,9325.0,9183.0,9056.0,9110.0,9149.0,9121.0,8930.0,8763.0,8714.0,8750.0,8542.0,8477.0,8630.0,8583.0,8470.0,8331.0,7915.0,7927.0,7946.0,7933.0,7734.0,7632.0,7375.0,7230.0,7375.0,7187.0,7153.0,7645.0,7430.0,7427.0,7527.0,7484.0,7478.0,7328.0,7426.0,7423.0,7491.0,7313.0,7318.0,7415.0,7423.0,7095.0,7337.0,6882.0,6979.0,7031.0,7236.0,7253.0,7158.0,7102.0,7000.0,6873.0,6655.0,6799.0,6655.0,6608.0,6656.0,6454.0,6308.0,6476.0,6368.0,6306.0,6422.0,5941.0,6047.0,6212.0,6259.0,6179.0,6300.0,6280.0,6100.0,6032.0,5976.0,6111.0,5783.0,6004.0,5796.0,5951.0,6025.0,5838.0,5915.0,5778.0,5716.0,5653.0,5708.0,5858.0,5733.0,5481.0,5758.0,5651.0,5747.0,5853.0,5625.0,5534.0,5639.0,5634.0,6023.0,6089.0,6141.0,6271.0,6226.0,6484.0,6583.0,7042.0,7142.0,7694.0,8003.0,8258.0,8182.0,8215.0,8304.0,8599.0,8399.0,8393.0,8390.0,8304.0,8251.0,8307.0,8520.0,8640.0,8520.0,8618.0,8588.0,8842.0,8957.0,9266.0,9011.0,8896.0,8921.0,8732.0,8576.0,8317.0,8370.0,8167.0,8491.0,8170.0,8212.0,8286.0,8136.0,7990.0,7927.0,8061.0,7932.0,7934.0,7784.0,7980.0,7737.0,7672.0,7651.0,7524.0,7406.0,7345.0,7553.0,7453.0,7566.0,7279.0,7064.0,7184.0,7072.0,7120.0,6980.0,7001.0,7175.0,7091.0,6847.0,6727.0,6872.0,6762.0,7116.0,6927.0,6731.0,6850.0,6766.0,6979.0,7149.0,7067.0,7170.0,7237.0,7240.0,7645.0,7685.0,7497.0,7822.0,7637.0,8395.0,8575.0,8937.0,9438.0,9494.0,10074.0,10538.0,11286.0,12058.0,12898.0,13426.0,13853.0,14499.0,14707.0,14601.0,14814.0,15009.0,15352.0,15219.0,15098.0,15046.0,15113.0,15202.0,15325.0,14849.0,14474.0,14512.0,14648.0,14579.0,14516.0,15081.0,14348.0,14013.0,13820.0,13737.0,13957.0,13855.0,13962.0,13763.0,13818.0,13948.0,13594.0,13302.0,13093.0,12797.0,12813.0,12713.0,12646.0,12660.0,12692.0,12656.0,12471.0,12115.0,12124.0,12005.0,12298.0,12471.0,11950.0,11689.0,11760.0,11654.0,11751.0,11335.0,11279.0,11270.0,11136.0,10787.0,10404.0,10202.0,10349.0,10380.0,9702.0,9859.0,9460.0,9608.0,9599.0,9262.0,8990.0,9090.0,8717.0,8903.0,8610.0,8504.0,8526.0]\n",
       "},\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"line\",\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"rownames\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"date\"\n",
       "},{\n",
       "\"type\":\"float\",\n",
       "\"column\":\"pce\"\n",
       "},{\n",
       "\"type\":\"float\",\n",
       "\"column\":\"pop\"\n",
       "},{\n",
       "\"type\":\"float\",\n",
       "\"column\":\"psavert\"\n",
       "},{\n",
       "\"type\":\"float\",\n",
       "\"column\":\"uempmed\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"unemploy\"\n",
       "}]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"plot_title\":{\n",
       "\"face\":\"bold\",\n",
       "\"size\":18.0,\n",
       "\"blank\":false\n",
       "},\n",
       "\"legend_position\":\"top\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"VkYrTg\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val breaks = listOf(2.5, 5.0, 10.0)\n",
    "\n",
    "letsPlot() +\n",
    "    geomBand(data = presidentialDf.toMap(), size = 0, alpha = 0.4) { xmin = \"start\"; xmax = \"end\"; fill = \"party\" } +\n",
    "    geomLabel(data = presidentialDf.toMap(), y = 4_000, alpha = 0.6, angle = 90, vjust = 1, showLegend = false)\n",
    "        { x = \"start\"; label = \"name\"; color = \"party\" } +\n",
    "    geomLine(data = economicsDf.toMap()) { x = \"date\"; y = \"unemploy\" } +\n",
    "    scaleXDateTime(name = \"Year\") +\n",
    "    scaleYContinuous(\"Unemployment (x\\\\(10^3\\\\))\", trans = \"log10\",\n",
    "                     breaks = breaks.map { it * 10.0.pow(3) },\n",
    "                     labels = breaks.map { it.toString() }) +\n",
    "    scaleFillDiscrete(name = \"\") +\n",
    "    coordCartesian(xlim = Pair(millisByYear(1966), millisByYear(2016))) +\n",
    "    guides(fill = guideLegend(alpha = 0.4, color = \"paper\")) +\n",
    "    ggsize(1000, 400) +\n",
    "    ggtitle(\"Unemployment in the US\", \"1967 to 2015\") +\n",
    "    theme(plotTitle = elementText(size = 18, face = \"bold\")).legendPositionTop()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.9.23"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
